<?php

namespace app\common\model;

use think\facade\Env;
use think\Model;

class Domain extends Model {

    /**
     * 定义主键
     * @var string
     */
    protected $pk = 'domain_id';
    
    /**
     * @desc 获取域名
     * @param int $userId
     * @return string
     * @throws \Exception
     */
    public function getDomain($userId) {
        $where = [
            ['domain_user_id', '=', $userId],
            ['domain_status', '=', DOMAIN_STATUS_YES]
        ];
        $result = $this->where($where)->order('domain_id', 'desc')->find();
        if(!$result) {
            $downloadUrl = Env::get('app.short_url');
        }else {
            $downloadUrl = $result['domain_http_protocol'].'://'.$result['domain_name'];
        }
        return  $downloadUrl;
    }
}